{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8d9ef590-ee26-482b-8c0a-ceb0ee307272",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "db3ad23c-c89a-4f5a-a45c-b2d5426982ff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle \\frac{1}{P V} \\frac{T}{P^{2} V}\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle \\frac{1}{P V} \\frac{T}{P^{2} V}$"
      ],
      "text/plain": [
       "1/(P*V) T/(P^2*V)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#### 通义千问那边的参考\n",
    "# 导入必要的变量\n",
    "P, T, V = var('P T V')\n",
    "\n",
    "# 定义状态方程，这里以理想气体为例：PV=nRT，假设nR=1简化处理\n",
    "# 实际应用时应替换为具体物质的状态方程\n",
    "state_eq = P * V == T\n",
    "\n",
    "# 计算等压膨胀系数 α\n",
    "alpha_expr = (1/V) * diff(V.subs(solve(state_eq, V)[0]), T)\n",
    "alpha_expr_simplified = alpha_expr.simplify_full()\n",
    "\n",
    "# 计算等温压缩系数 β\n",
    "beta_expr = -(1/V) * diff(V.subs(solve(state_eq, V)[0]), P)\n",
    "beta_expr_simplified = beta_expr.simplify_full()\n",
    "\n",
    "show(alpha_expr_simplified, beta_expr_simplified)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "8471609b-643e-4253-99f8-9665eea4e3f6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle \\frac{\\frac{\\partial}{\\partial T}V\\left(T, P\\right)}{V\\left(T, P\\right)}\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle \\frac{\\frac{\\partial}{\\partial T}V\\left(T, P\\right)}{V\\left(T, P\\right)}$"
      ],
      "text/plain": [
       "diff(V(T, P), T)/V(T, P)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle -\\frac{\\frac{\\partial}{\\partial P}V\\left(T, P\\right)}{V\\left(T, P\\right)}\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle -\\frac{\\frac{\\partial}{\\partial P}V\\left(T, P\\right)}{V\\left(T, P\\right)}$"
      ],
      "text/plain": [
       "-diff(V(T, P), P)/V(T, P)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "## deepseek的参考\n",
    "# 定义符号变量和函数\n",
    "T, P = var('T P')\n",
    "V = function('V')(T, P)\n",
    "\n",
    "# 等压膨胀系数 β = (1/V) * (∂V/∂T)_P\n",
    "beta = (1/V) * diff(V, T)\n",
    "\n",
    "# 等温压缩系数 κ_T = -(1/V) * (∂V/∂P)_T\n",
    "kappa_T = -(1/V) * diff(V, P)\n",
    "\n",
    "# 以LaTeX形式显示\n",
    "show(beta)\n",
    "show(kappa_T)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "22f1d44d-7f6d-4034-a5a9-7af34df4cb48",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle \\beta = \\frac{\\left(\\frac{\\partial V}{\\partial T}\\right)_{P}\\left(T, P\\right)}{V\\left(T, P\\right)}\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle \\beta = \\frac{\\left(\\frac{\\partial V}{\\partial T}\\right)_{P}\\left(T, P\\right)}{V\\left(T, P\\right)}$"
      ],
      "text/plain": [
       "\\beta = \\frac{\\left(\\frac{\\partial V}{\\partial T}\\right)_{P}\\left(T, P\\right)}{V\\left(T, P\\right)}"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html>\\(\\displaystyle \\kappa_T = -\\frac{\\left(\\frac{\\partial V}{\\partial P}\\right)_{T}\\left(T, P\\right)}{V\\left(T, P\\right)}\\)</html>"
      ],
      "text/latex": [
       "$\\displaystyle \\kappa_T = -\\frac{\\left(\\frac{\\partial V}{\\partial P}\\right)_{T}\\left(T, P\\right)}{V\\left(T, P\\right)}$"
      ],
      "text/plain": [
       "\\kappa_T = -\\frac{\\left(\\frac{\\partial V}{\\partial P}\\right)_{T}\\left(T, P\\right)}{V\\left(T, P\\right)}"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# deepseek修改版\n",
    "# 定义符号变量和函数（隐藏V的参数显示）\n",
    "T, P = var('T P')\n",
    "V = function('V', latex_name=r'V')(T, P)  # 使用latex_name使V显示为V而非V(T,P)\n",
    "\n",
    "# 定义等压膨胀系数和等温压缩系数\n",
    "beta = (1/V) * diff(V, T)\n",
    "kappa_T = -(1/V) * diff(V, P)\n",
    "\n",
    "# 自定义偏导数的LaTeX表示（添加下标）\n",
    "def format_derivative(latex_str, var, hold_var):\n",
    "    return latex_str.replace(\n",
    "        r'\\frac{\\partial}{\\partial ' + var + r'}V',\n",
    "        r'\\left(\\frac{\\partial V}{\\partial ' + var + r'}\\right)_{' + hold_var + r'}'\n",
    "    )\n",
    "\n",
    "# 生成并优化LaTeX输出\n",
    "beta_tex = format_derivative(latex(beta), 'T', 'P')\n",
    "kappa_T_tex = format_derivative(latex(kappa_T), 'P', 'T')\n",
    "\n",
    "# 显示结果\n",
    "from sage.misc.latex import LatexExpr\n",
    "show(LatexExpr(r'\\beta = ' + beta_tex))\n",
    "show(LatexExpr(r'\\kappa_T = ' + kappa_T_tex))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "SageMath 10.5",
   "language": "sage",
   "name": "sagemath"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
